<?php

use yii\db\Migration;

/**
 * Class m220816_071819_config_init
 *
 * 数据迁移，控制台操作
 * ```
 * yii migrate --migrationPath=@vii/config/migrations
 * ```
 *
 * @author Fakis <fakis738@qq.com>
 */
class m220816_071819_config_init extends Migration
{
    /**
     * {@inheritdoc}
     * @throws \yii\base\Exception
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4';
        }

        $this->createTable('{{%config}}', [
            'symbol' => $this->string(64)->notNull()->comment('标识'),
            'data' => $this->json()->comment('配置数据'),
            'PRIMARY KEY ([[symbol]])',
        ], $tableOptions);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable('{{%config}}');
    }
}
